package com.activenetwork.smlite.testcase.events.createEvents.basics;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.activenetwork.schema.model.event.EventBasicType;
import com.activenetwork.smlite.page.event.EventDetailView.EventBasicSubview;
import com.activenetwork.smlite.page.generic.ModelPage;
import com.activenetwork.smlite.snippet.EventsSnippet;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.PageLoader;
import com.activenetwork.util.verification.gson.FailurePoint;

public class Basics019 extends BaseCase {
	static final Logger logger = LoggerFactory.getLogger(Basics019.class);
	private EventBasicType.Tag privateTag;
	private EventBasicType.Tag publicTag;
	private String accountA[];
	private String accountB[];
	
	@BeforeClass(alwaysRun = true)
	public void dataSetup(){
		privateTag = new EventBasicType.Tag();
		privateTag.setTagName("autotest-private-tag");
		privateTag.setTagDesc("autotest-private-tag");
		privateTag.setPrivate(true);
		
		publicTag = new EventBasicType.Tag();
		publicTag.setTagName("autotest-public-tag");
		publicTag.setTagDesc("autotest-public-tag");
		publicTag.setPrivate(false);
		
		accountA = new String[]{"smlite@starcite.com", "st@rc!te"};
		accountB = new String[]{"helen.yuan@starcite.com", "111111"};
	}
	
	@Test
	public void Verify_isPrivate_feature_of_new_Tag(){	
		// Setup private tag under accountA
		loginBusiness.login(accountA[0], accountA[1]);
		EventBasicSubview eventBasicSubview = EventsSnippet.gotoAddEventPage();
		
		eventBasicSubview = eventBasicSubview.setTag(privateTag);
		eventBasicSubview = eventBasicSubview.saveTag();
		loginBusiness.logout();
		
		// Setup public tag under accountB
		loginBusiness.login(accountB[0], accountB[1]);
		eventBasicSubview = EventsSnippet.gotoAddEventPage();
		
		eventBasicSubview = eventBasicSubview.setTag(publicTag);
		eventBasicSubview = eventBasicSubview.saveTag();
		
		// expect private tag can not be seen under accountB
		eventBasicSubview = EventsSnippet.gotoAddEventPage();
		
		try{
			eventBasicSubview.selectEventTagAJAX(privateTag);
			EnvContext.failurePointTL.get().add(
					new FailurePoint(Basics019.class.getName(), 
					"Verify tag privacy", 
					"Private tag can be seen under other account. Not correct. "));
		}catch(RuntimeException e){
			logger.info("Success of verifying private tag in other account");
		}
		
		// expect public tag can be seen under accountB
		eventBasicSubview = EventsSnippet.gotoAddEventPage();
		
		try{
			eventBasicSubview.selectEventTagAJAX(publicTag);
			logger.info("Success of verifying public tag in owner account");
		}catch(RuntimeException e){
			EnvContext.failurePointTL.get().add(
					new FailurePoint(Basics019.class.getName(), 
					"Verify tag privacy", 
					"Public tag can NOT be seen under owner account. Not correct. "));
		}
		
		// expect private tag can be seen under accountA
		PageLoader.load(ModelPage.class).logout();
		loginBusiness.login(accountA[0], accountA[1]);
		eventBasicSubview = EventsSnippet.gotoAddEventPage();
		
		try{
			eventBasicSubview.selectEventTagAJAX(privateTag);
			logger.info("Success of verifying private tag in owner account");
		}catch(RuntimeException e){
			EnvContext.failurePointTL.get().add(
					new FailurePoint(Basics019.class.getName(), 
					"Verify tag privacy", 
					"Private tag can NOT be seen under owner account. Not correct. "));
		}
		
		// expect public tag can be seen under accountA
		eventBasicSubview = EventsSnippet.gotoAddEventPage();
		
		try{
			eventBasicSubview.selectEventTagAJAX(publicTag);
			logger.info("Success of verifying public tag in other account");
		}catch(RuntimeException e){
			EnvContext.failurePointTL.get().add(
					new FailurePoint(Basics019.class.getName(), 
					"Verify tag privacy", 
					"Public tag can NOT be seen under other account. Not correct. "));
		}
		
		
		loginBusiness.logout();
		
	}
}
